package com.domain;

import java.sql.SQLException;
import java.util.Collection;
import java.util.Iterator;

import com.dao.CallesDAO;
import com.dao.ConnectionManager;
import com.dao.EsquinaDAO;
import com.vo.Calles;
import com.vo.Esquina;

public class CallesDomain {

	private static CallesDomain instance=null;
	
	public static CallesDomain getInstance(){
		if(instance==null){
			instance=new CallesDomain();
		}
		return instance;
	}
	
	private CallesDomain(){}
	
	public Esquina getEsquina(int calle1,int calle2) throws SQLException{
		EsquinaDAO dao=EsquinaDAO.create(ConnectionManager.getInstance().getConnection());
		return dao.retrieve(calle1, calle2);
	}
	
	public Collection<Calles> getCalleLike(String calle1) throws SQLException{
		CallesDAO dao=CallesDAO.create(ConnectionManager.getInstance().getConnection());
		return dao.retrieveLike(calle1);
	}
	
	public String[] getCallesFromEsquinas(Integer idEsquina1, Integer idEsquina2) throws SQLException{
		CallesDAO dao=CallesDAO.create(ConnectionManager.getInstance().getConnection());
		Collection calles=dao.obtenerCallesPorEsquinas(idEsquina1, idEsquina2);
		String[] strCalles=new String[calles.size()];
		Iterator it=calles.iterator();
		int count=0;
		while(it.hasNext()){
			strCalles[count]=((Calles)it.next()).getNombre();
			count++;
		}
		return strCalles;
	}
	
	public String[] getCallesFromEsquina(Integer idEsquina) throws SQLException{
		CallesDAO dao=CallesDAO.create(ConnectionManager.getInstance().getConnection());
		Collection calles=dao.obtenerCallesPorEsquina(idEsquina);
		String[] strCalles=new String[calles.size()];
		Iterator it=calles.iterator();
		int count=0;
		while(it.hasNext()){
			strCalles[count]=((Calles)it.next()).getNombre();
			count++;
		}
		return strCalles;
	}
	
}
